Jump to content

Wikidata/Notes/Inclusion syntax v0.3

From Meta, a Wikimedia project coordination wiki

Obsolete

This draft is obsolete and only kept for reference. Please refer to Wikidata/Notes/Inclusion_syntax for the current version
New Version (January 2013) This is a completely reworked proposal with little resemblance to the previous drafts!

This page describes the data inclusion syntax for the Wikibase client, by which the properties of data items can be included and rendered on a wiki page using templates. In short: This is how we want Wikipedia articles to include data from Wikidata.

Preliminary

[edit]

The inclusion syntax presented here is meant to work for simple cases, and only for them.

Complicated cases are currently planned to be realized using Lua. We do not know yet how the binding to Lua will look like, but we are confident that it will be far easier to use than any binding to Wikitext could ever look like. (Lua would be able to access Wikidata items and then programmatically work on them).

Accessing Item Data

[edit]

Properties of a Wikidata Item can be used via the #property parser function:

 {{#property:population}}

This will provide a representation of the value of the population property of the page's default item. The default item is the Wikidata item that is associated with this page via language links.

To access properties of a different item, it has to be specified explicitly, either by id

 {{#property:population|id=q12345}}

or the associated Wiki page

 {{#property:population|of=Germany}}

(Note that the parameter name "of" works pretty nicely in English, but in other languages we will most likely need to use some other word here, like "item" or "about" or something, because a direct translation of "of" might lead to problems with cases.)

Current status

[edit]

On it: (one of the wikis where this has been deployed, see Wikidata/Deployment Questions#When will this be deployed on my Wikipedia? and d:Wikidata:Introduction#What do we have so far?) the current status is as follows.

For example, on it:Germania, , referring to the property "capital" with the page d:Property:P36, gives "Berlino".

However, the following does not work (yet):

  • specifying a property by name (see also en:Wikipedia:Wikidata/Workflow#Discovering property IDs: "we're working on making it possible to use chief executive officer instead of the id.")
  • accessing properties of a different item, such as putting on another page of it:, referring to the value of the property specified on d:Q183 (the Wikidata page on Germany) (see [1]: "Currently we only support transclusion of data from the item that is directly linked to the page.")

Formatting of qualified and sourced values

[edit]

All values that are preferred are returned. The values also include qualifiers and references.

There are a number of further parameters that can be used to fine-tune the formatting:

  • separator: if there are several values, this is used to separate the values
  • value template: a template to call on each value, with the parameters value, qualifiers and references
  • qualifier template: a template to call on each qualifier, using the qualifier property label as the first and the qualifier values as the second parameter. Ignored if there is a qualifiers template.
  • qualifier separator: if there are several qualifiers, this is used to separate them. Ignored if there is a qualifiers template.
  • qualifiers wrapper: a template to call on the qualifiers, using the qualifiers as the parameter. Ignored if there is a qualifiers template. Ignored if there are no qualifiers.
  • qualifiers template: a template to call for all qualifiers, using the qualifier property labels as the argument names and the values as the respective value.
  • qualifiers value separator: if a single qualifier has several values, this is used to separate these values
  • reference keyvalue template: a template to call on each key-value pair of a reference, using the key label as the first and the values as the second parameter. Ignored if there is a reference template.
  • reference wrapper: a template to call on each reference, using the reference as the parameter. Ignored if there is a reference template.
  • references wrapper: a template to call on all references, using the references as the parameter. Ignored if there is a reference template. Ignored if there are nor references.
  • reference keyvalue separator: if there are several key-value pairs in one reference, this is used to separate them. Ignored if there is a reference template.
  • reference template: a template to call on each references of a value, using the key labels as the argument names and the values as the respective value.
  • reference value separator: if within a reference one key has several values, this is used to separate these values
  • reference separator: a separator to use between each reference

There is a (sensible) default value for each of these which can be changed per wiki using the messaging system.

Once you have seen this parameter list, you might understand why we want to use Lua for anything that is not "simple".

Formatting of single values

[edit]

Items

[edit]
  • item display template: a template that is called for items, with the named parameters label, link, id, description and property

Number

[edit]
  • number display template: a template that is called for numbers, with the named parameters formatted value, value, unit, ... (to be defined once the data model is fixed)

Time

[edit]
  • time display template: a template that is called for times, with the named parameters iso8601, year, month, ... (to be defined once the data model is fixed)

Coordinate

[edit]
  • coordinate display template: a template that is called for coordinates, with the named parameters latitude, longitude, latitude dms, ... (to be defined once the data model is fixed)

Other

[edit]

To be defined

Examples

[edit]

Assumptions

[edit]

The example assume reasonable default values for the above arguments. The examples assume no references, for simplicity sake. We assume here:

  • separator: ,
  • value template: {{{value}}} {{{qualifiers}}}{{{references}}}
  • qualifier template: {{{1}}} {{{2}}}
  • qualifier separator: ,
  • qualifiers wrapper: ({{{1}}})
  • qualifiers template: empty
  • qualifiers value separator: ,
  • reference keyvalue template: {{{1}}} {{{2}}}
  • reference wrapper: <ref>{{{1}}}</ref>
  • references wrapper: {{{1}}}
  • reference keyvalue separator: ,
  • reference template: empty
  • reference value separator: ,
  • reference separator: a separator to use between each reference

Example 1

[edit]

Given the following statement:

Berlin


Population3,500,000[no sources]
as of 2012

{{#property:population}} will display as "3,500,000 (as of 2012)"

Example 2

[edit]

Given the following statement:

Germany


ChancellorAngela Merkel[2 sources]
since 2005
Party CDU

and assuming that Template:Nothing is defined as empty, and there are articles for Angela Merkel and the CDU in the client wiki and these articles are linked to Wikidata:

Example 3

[edit]

Given the following statement:

Mumbai


Population12,479,608[1 source]
as of 2011
Method Census
21,000,000[2 sources]
Method Estimate

and assuming that Template:Nothing is defined as empty, and there are articles for Estimate but not for Census in the client wiki and Estimate is linked to Wikidata and the Census item has a label:

  • {{#property:Population}} will display as "12,479,608 (as of 2011, Method Census)[5], 21,000,000 (Method Estimate)[6][7]"
  • {{#property:Population|qualifiers template=Nothing|separator= or }} will display as "12,479,608[8] or 21,000,000[9][10]"
  • {{#property:Population|qualifiers template=Nothing|reference template=Nothing|separator= or }} will display as "12,479,608 or 21,000,000"

Fake references from the examples

[edit]
  1. Reference 1
  2. Reference 2
  3. Reference 1
  4. Reference 2
  5. Reference 3
  6. Reference 4
  7. Reference 5
  8. Reference 3
  9. Reference 4
  10. Reference 5

See also

[edit]